import java.awt.Point;
import java.util.ArrayList;

/**
 * Class for the chess piece of a Knight
 * 
 * @author Sabrina Gaudreau
 * @version Jan, 23/2010
 */
public class Knight extends Piece
{
    /**
     * Constructor for objects of class Knight
     * 
     */
    public Knight(int x, int y)
    {
        // Sets the initial coordinates
        super(x,y);
    }
    
    /**
     * Overrides abstract method in class Piece.
     * Calculates list of all possible moves of the Knight
     * at its current position.
     * 
     * @author Sabrina Gaudreau, modified by Jordan Beland
     * @return ArrayList<Point>
     */
    @Override
    public ArrayList<Point> possibleMoves()
    {
        int x = super.getX();
        int y = super.getY();
        ArrayList<Point> moves = new ArrayList<Point>();
        
        //all possible moves in the up direction (up right and up left)
        if(x+1 < Board.SIZE && y-2 >= 0)moves.add(new Point(x+1, y-2));
        if(x-1 >= 0 && y-2 >= 0)moves.add(new Point(x-1, y-2));
        
        //all possible moves in the down direction (down right and down left)
        if(x+1 < Board.SIZE && y+2 < Board.SIZE)moves.add(new Point(x+1, y+2));
        if(x-1 >= 0 && y+2 < Board.SIZE)moves.add(new Point(x-1, y+2));
        
        //all possible moves in the left direction (left up and left down)
        if(x-2 >= 0 && y-1 >= 0)moves.add(new Point(x-2, y-1));
        if(x-2 >= 0 && y+1 < Board.SIZE)moves.add(new Point(x-2, y+1));
        
        //all possible moves in the right direction (right up and right down)
        if(x+2 < Board.SIZE && y-1 >= 0)moves.add(new Point(x+2, y-1));
        if(x+2 < Board.SIZE && y+1 < Board.SIZE)moves.add(new Point(x+2, y+1));
        
        return moves;
    }
    
    /**
     * Move in a horse direction unless the horse was previously there
     */
    public void move(int x,int y){
        setX(x);
        setY(y);
    }
        
}

